# PowerShell build script for RISC-V minimal OS

Write-Host "Building RISC-V minimal OS..." -ForegroundColor Green

# Check if make is available
try {
    $null = Get-Command make -ErrorAction Stop
    Write-Host "Make found" -ForegroundColor Green
} catch {
    Write-Host "Error: make is not installed or not in PATH" -ForegroundColor Red
    Write-Host "Please install make or add it to your PATH" -ForegroundColor Yellow
    Read-Host "Press Enter to exit"
    exit 1
}

# Check if RISC-V GCC is available
try {
    $null = Get-Command riscv64-unknown-elf-gcc -ErrorAction Stop
    Write-Host "RISC-V GCC found" -ForegroundColor Green
} catch {
    Write-Host "Error: riscv64-unknown-elf-gcc is not installed or not in PATH" -ForegroundColor Red
    Write-Host "Please install RISC-V toolchain" -ForegroundColor Yellow
    Read-Host "Press Enter to exit"
    exit 1
}

# Clean previous build
Write-Host "Cleaning previous build..." -ForegroundColor Yellow
& make clean

# Build the kernel
Write-Host "Building kernel..." -ForegroundColor Yellow
& make

if ($LASTEXITCODE -eq 0) {
    Write-Host "Build successful!" -ForegroundColor Green
    Write-Host ""
    Write-Host "To run in QEMU, use: make run" -ForegroundColor Cyan
    Write-Host "To debug, use: make debug" -ForegroundColor Cyan
} else {
    Write-Host "Build failed!" -ForegroundColor Red
}

Read-Host "Press Enter to exit"
